package itheima.mapper;

import itheima.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.junit.Assert.*;

public class UserMapperTest2 {

    @Test
    public void queryUserById() {
       /* 装配sqlsessionfactory
       ApplicationContext ap=new ClassPathXmlApplicationContext("spring/applicationcontext.xml");
        SqlSessionFactory sf = (SqlSessionFactory) ap.getBean("SqlSessionFactory");
       SqlSession sqlsession= sf.openSession(true);
       UserMapper userMapper=sqlsession.getMapper(UserMapper.class);
       User user=userMapper.queryUserById(1l);
        System.out.println(user);
*/
    /*   装配单个mapper
     ApplicationContext ap = new ClassPathXmlApplicationContext("spring/applicationcontext.xml");
        UserMapper um = (UserMapper) ap.getBean("usermapper");
        User user = um.queryUserById(1l);
        System.out.println(user);
*/
    //装配多个mapper
        ApplicationContext ap = new ClassPathXmlApplicationContext("spring/applicationcontext.xml");
        UserMapper um=ap.getBean(UserMapper.class);
        User user=um.queryUserById(1l);
        System.out.println(user);
    }
}